﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SRW;
using SRW.BLL;
using System.Collections.Generic;

public partial class system_xtgl_outWeb : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            AspNetPager1.RecordCount = SQL.ExecScalar("select count(*) from wtlink");
            AspNetPager1.PageSize = 9;

            PageData.bindData(Repeater1, "select * from wtlink", "wtlink", AspNetPager1);
        }
    }
    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        PageData.bindData(Repeater1, "select * from wtlink", "wtlink", AspNetPager1);
    }
    protected void LinkBupdateClick(object sender, EventArgs e)
    {
        LinkButton d = (LinkButton)sender;
        string productid = d.CommandArgument;
        Label3.Text = productid;
        TB_linkname.Text = SQL.GetData("select linkname from wtlink where pkID=" + int.Parse(productid) + "", "linkname");
        TB_linkplace.Text = SQL.GetData("select linkplace from wtlink where pkID=" + int.Parse(productid) + "", "linkplace");
        Button1.Text = "修  改";
    }
    protected void LinkBdeleteClick(object sender, EventArgs e)
    {
        LinkButton d = (LinkButton)sender;
        string productid = d.CommandArgument;
        Label3.Text = productid;
        TB_linkname.Text = SQL.GetData("select linkname from wtlink where pkID=" + int.Parse(productid) + "", "linkname");
        TB_linkplace.Text = SQL.GetData("select linkplace from wtlink where pkID=" + int.Parse(productid) + "", "linkplace");
        Button1.Text = "删  除";
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        TB_linkname.Text = "";
        TB_linkplace.Text = "";
        Button1.Text = "添  加";
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (Button1.Text.Equals("添  加"))
        {
            Wtlink mWtlink = new Wtlink();
            mWtlink.linkname = TB_linkname.Text;
            mWtlink.linkplace = TB_linkplace.Text;
            if (bWtlink.Insert(mWtlink, false))
            {
                MagicAjax.AjaxCallHelper.WriteAlert("添加成功");
                PageData.bindData(Repeater1, "select * from wtlink", "wtlink", AspNetPager1);
            }
        }
        else if (Button1.Text.Equals("删  除"))
        {
            if (bWtlink.Delete(int.Parse(Label3.Text)))
            {
                MagicAjax.AjaxCallHelper.WriteAlert("删除成功");
                PageData.bindData(Repeater1, "select * from wtlink", "wtlink", AspNetPager1);
            }
        }
        else
        {
            Wtlink mWtlink = new Wtlink();
            mWtlink.pkID = int.Parse(Label3.Text);
            mWtlink.linkname = TB_linkname.Text;
            mWtlink.linkplace = TB_linkplace.Text;
            if (bWtlink.Update(mWtlink,true))
            {
                MagicAjax.AjaxCallHelper.WriteAlert("修改成功");
                PageData.bindData(Repeater1, "select * from wtlink", "wtlink", AspNetPager1);
            }
        }
        TB_linkname.Text = "";
        TB_linkplace.Text = "";
        Button1.Text = "添  加";
    }
    protected void CB_AllCheckedChanged(object sender, EventArgs e)
    {
        CB_All.Checked = true;
        CB_FXSelect.Checked = false;
        foreach (RepeaterItem item in this.Repeater1.Items)
        {
            CheckBox CB_ALLSelect = (CheckBox)item.FindControl("CB_ALLSelect");
            if (!CB_ALLSelect.Checked)
            {
                CB_ALLSelect.Checked = true;
            }
        }
    }
    protected void CB_FXSelect_CheckedChanged(object sender, EventArgs e)
    {
        CB_FXSelect.Checked = true;
        CB_All.Checked = false;
        foreach (RepeaterItem item in this.Repeater1.Items)
        {
            CheckBox CB_ALLSelect = (CheckBox)item.FindControl("CB_ALLSelect");
            if (CB_ALLSelect.Checked)
            {
                CB_ALLSelect.Checked = false;
            }
            else
            {
                CB_ALLSelect.Checked = true;
            }
        }
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        List<string> SQLStringList = new List<string>();
        for (int i = 0; i < Repeater1.Items.Count; i++)
        {
            RepeaterItem reItem = (RepeaterItem)Repeater1.Items[i];
            Label Label1 = (Label)reItem.FindControl("Label1");
            CheckBox CB_ALLSelect = (CheckBox)reItem.FindControl("CB_ALLSelect");
            if (CB_ALLSelect.Checked == true)
            {
                SQLStringList.Add("delete from wtlink where pkID=" + int.Parse(Label1.Text) + "");
            }
        }
        if (SQL.ExecuteSqlTran(SQLStringList))
        {
            MagicAjax.AjaxCallHelper.WriteAlert("删除成功");
            PageData.bindData(Repeater1, "select * from wtlink", "wtlink", AspNetPager1);
        }
    }
}
